home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 05 / BitLogic.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  704 b   |  20 lines

  1. class Bitlogic {
  2. public static void main(String args []) { 
  3. String binary[] = { "OOOO", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",    "1010", "1011", "1100", "1101",
  4. "1110", "1111" };
  5. int a = 3;    //    0+2+1    ¿½¿ ñó«¿τ¡«Ñ 0011
  6. int b = 6;    //    4+2+0    ¿½¿ ñó«¿τ¡«Ñ 0110
  7. int c = a | b;
  8. int d = a & b;
  9. int e = a ^ b;
  10. int f = (~a & b) | (a & ~b);
  11. int g = ~a & 0x0f;
  12. System.out.println(" a = " + binary[a]);
  13. System.out.println(" b = " + binary[b]);
  14. System.out.println(" ab = " + binary[c]);
  15. System.out.println(" a&b = " + binary[d]);
  16. System.out.println(" a^b = " + binary[e]);
  17. System.out.println("~a&b | á^~b = " + binary[f]);
  18. System.out.println(" ~a = " + binary[g]);
  19. } }
  20.